/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.sober;

import com.jspx.sober.dialect.Dialect;
import com.jspx.sober.config.SQLRoom;
import com.jspx.sober.transaction.AbstractTransaction;

import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.io.Serializable;
import java.sql.SQLException;


/**
 * Created by IntelliJ IDEA.
 * User:chenYuan (mail:39793751@qq.com)
 * Date: 2007-1-6
 * Time: 23:36:39
 */
public interface SoberFactory extends Serializable
{
    int getMaxRows();

    void setMaxRows(int maxRows);

    /**
     * jdbc fetch Size
     * @param fetchSize  jdbc 参数
     */
    void setFetchSize(int fetchSize);

    int getFetchSize();

    String getDatabaseName();

    Dialect getDialect();

    DataSource getDataSource();

    Connection getConnection(int type,int tid) throws Exception;

    void closeConnection(Connection conn,boolean  release);

    TableModels getTableModels(Class cla, SoberSupport soberSupport);

    boolean isShowsql();

    boolean isAutoCommit();

    int getTransactionIsolation();

    void setTransactionIsolation(int transactionIsolation);

    SQLRoom getSQLRoom(Class cla);

    SQLRoom getSQLRoom(String namespace);

    void setMappingResources(String[] strings) throws Exception;

    boolean isValid();

    void setValid(boolean valid);

    void clear();

    /**
     * 创建一个事务 创建事务
     * @param soberSupport
     * @return
     * @throws Exception
     */
    AbstractTransaction createTransaction(SoberSupport soberSupport) throws SQLException;

    /**
     *
     * @return 事务超时
     */
    int getTransactionTimeout();

    /**
     *
     * @return 使用jta 分布式事务
     */
    boolean isJta();
    /**
     *
     * @return 状态缓存名称,为了分布式缓存方便
     */
    String getStateCache();

    /**
     *
     * @return 得到默认缓存名称
     */
    String getCacheName();

    /**
     *
     * @return 锁定标识的缓存时间
     *  int getLockTimeout();
     */


    /**
     *
     * @return 是否使用缓存
     */
    boolean isUseCache();


    /*

    boolean isLock(Class aclass, Serializable field, Serializable serializable);

    //状态缓存里边标识锁定对象
    void lock(Class cla, Serializable field,  Serializable serializable);

   //状态缓存里边删除锁定id
    void unLock(Class cla, Serializable field,  Serializable serializable);

    */
}